package com.new_wear.project.system.pos.controller;

import java.util.List;

import com.new_wear.project.system.info.domain.CstAdInfo;
import com.new_wear.project.system.info.service.ICstAdInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.new_wear.framework.aspectj.lang.annotation.Log;
import com.new_wear.framework.aspectj.lang.enums.BusinessType;
import com.new_wear.project.system.pos.domain.CstAdPos;
import com.new_wear.project.system.pos.service.ICstAdPosService;
import com.new_wear.framework.web.controller.BaseController;
import com.new_wear.framework.web.domain.AjaxResult;
import com.new_wear.common.utils.poi.ExcelUtil;
import com.new_wear.framework.web.page.TableDataInfo;

/**
 * 广告 - 广告位Controller
 * 
 * @author new_wear
 * @date 2019-12-20
 */
@Controller
@RequestMapping("/system/pos")
public class CstAdPosController extends BaseController
{
    private String prefix = "system/pos";

    @Autowired
    private ICstAdPosService cstAdPosService;
    @Autowired
    private ICstAdInfoService cstAdInfoService;

    @RequiresPermissions("system:pos:view")
    @GetMapping()
    public String pos()
    {
        return prefix + "/pos";
    }

    /**
     * 查询广告 - 广告位列表
     */

    @RequiresPermissions("system:pos:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CstAdPos cstAdPos)
    {
        startPage();
        List<CstAdPos> list = cstAdPosService.selectCstAdPosList(cstAdPos);
        return getDataTable(list);
    }

    /**
     * 导出广告 - 广告位列表
     */
    @RequiresPermissions("system:pos:export")
    @Log(title = "广告 - 广告位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CstAdPos cstAdPos)
    {
        List<CstAdPos> list = cstAdPosService.selectCstAdPosList(cstAdPos);
        ExcelUtil<CstAdPos> util = new ExcelUtil<CstAdPos>(CstAdPos.class);
        return util.exportExcel(list, "pos");
    }

    /**
     * 新增广告 - 广告位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广告 - 广告位
     */
    @RequiresPermissions("system:pos:add")
    @Log(title = "广告 - 广告位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CstAdPos cstAdPos)
    {
        return toAjax(cstAdPosService.insertCstAdPos(cstAdPos));
    }

    /**
     * 修改广告 - 广告位
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        CstAdPos cstAdPos = cstAdPosService.selectCstAdPosById(id);
        mmap.put("cstAdPos", cstAdPos);
        return prefix + "/edit";
    }

    /**
     * 修改保存广告 - 广告位
     */
    @RequiresPermissions("system:pos:edit")
    @Log(title = "广告 - 广告位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CstAdPos cstAdPos)
    {
        return toAjax(cstAdPosService.updateCstAdPos(cstAdPos));
    }

    /**
     * 删除广告 - 广告位
     */
    @RequiresPermissions("system:pos:remove")
    @Log(title = "广告 - 广告位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cstAdPosService.deleteCstAdPosByIds(ids));
    }


    @RequestMapping("/positions/{position}")
    public String addadpos( @PathVariable("position") Integer position,ModelMap map) {
        map.put("position",position);
        return prefix + "/see";
    }
    /*查看广告*/
    @RequestMapping("/seeposition/{position}")
    @ResponseBody
    public TableDataInfo see(@PathVariable("position")Integer position){
        CstAdInfo cstAdInfo = new CstAdInfo();
        cstAdInfo.setAdPos(position);
        List<CstAdInfo> cstAdInfoList = cstAdInfoService.selectCstAdInfoList(cstAdInfo);
        return getDataTable(cstAdInfoList);
    }
}
